﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Site.Infrastructure.Logging
{
    public class LogUtility
    {

        public static string BuildExceptionMessage(Exception e)
        {

            Exception logException = e;
            if (e.InnerException != null)
                logException = e.InnerException;


            StringBuilder sb = new StringBuilder();

            sb.Append(Environment.NewLine);
            sb.Append("Error in Path :");
            sb.Append(System.Web.HttpContext.Current.Request.Path);

            // Get the QueryString along with the Virtual Path
            sb.Append(Environment.NewLine);
            sb.Append("Raw Url :");
            sb.Append(System.Web.HttpContext.Current.Request.RawUrl);

            // Get the error message
            sb.Append(Environment.NewLine);
            sb.Append("Message :");
            sb.Append(logException.Message);

            // Source of the message
            sb.Append(Environment.NewLine);
            sb.Append("Source :");
            sb.Append(logException.Source);

            // Stack Trace of the error
            sb.Append(Environment.NewLine);
            sb.Append("Stack Trace :");
            sb.Append(logException.StackTrace);

            // Method where the error occurred
            sb.Append(Environment.NewLine);
            sb.Append("TargetSite :");
            sb.Append(logException.TargetSite);

            return sb.ToString();
        }
    }
}
